import request from './request'
import { useUserStore } from '../store/modules/user'
import { AxiosPromise } from 'axios'
// 获取设备单位列表
export function unitList(data: any) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    headers: token,
    url: '/goods/set/unit/getList',
    method: 'post',
    data,
  })
}

// 新增或修改单位
export function unitSave(data: any) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    headers: token,
    url: '/goods/set/unit/save',
    method: 'post',
    data,
  })
}

// 批量禁用或启用设备单位
export function unitDisable(data: any, status: boolean) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    headers: token,
    url: '/goods/set/unit/disable',
    method: 'put',
    data,
    params: { status },
  })
}

// 批量删除设备单位
export function unitDelete(data: any) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    headers: token,
    url: '/goods/set/unit/',
    method: 'delete',
    data,
  })
}

// 获取设备类型列表
export function typeList() {
  return request({
    url: '/goods/set/type/getList',
    method: 'post',
  })
}

// 新增或修改设备类型
export function typeSave(data: any) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    headers: token,
    url: '/goods/set/type/save',
    method: 'post',
    data,
  })
}

// 批量禁用或启用设备类型
export function typeDisable(data: any, status: boolean) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    headers: token,
    url: '/goods/set/type/disable',
    method: 'put',
    data,
    params: { status },
  })
}

// 批量删除设备类型
export function typeDelete(data: any) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    headers: token,
    url: '/goods/set/type/',
    method: 'delete',
    data,
  })
}

// 获取设备规格列表
export function specList(data: any) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    headers: token,
    url: '/goods/set/spec/getList',
    method: 'post',
    data,
  })
}

// 新增或修改设备规格
export function specSave(data: any) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    headers: token,
    url: '/goods/set/spec/save',
    method: 'post',
    data,
  })
}

// 批量禁用或启用设备规格
export function specDisable(data: any, params: boolean) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    headers: token,
    url: '/goods/set/spec/disable',
    method: 'put',
    data,
    params,
  })
}

// 批量删除设备规格
export function specDelete(data: any) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    headers: token,
    url: '/goods/set/spec/',
    method: 'delete',
    data,
  })
}

// 获取设备规格信息
export function specInfo(id: any) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    headers: token,
    url: '/goods/set/spec/' + id,
    method: 'get',
  })
}

// 获取设备字段列表
export function fieldList(data: any) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    headers: token,
    url: '/goods/set/field/getList',
    method: 'post',
    data,
  })
}

// 新增或修改设备字段
export function fieldSave(data: any) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    headers: token,
    url: '/goods/set/field/save',
    method: 'post',
    data,
  })
}

// 批量禁用或启用设备字段
export function fieldDisable(data: any, status: boolean) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    headers: token,
    url: '/goods/set/field/',
    method: 'put',
    data,
    params: { status },
  })
}

// 批量删除设备字段
export function fieldDelete(data: any) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    headers: token,
    url: '/goods/set/field/',
    method: 'delete',
    data,
  })
}

// 获取设备字段信息
export function fieldInfo(id: any) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    headers: token,
    url: '/goods/set/field/' + id,
    method: 'get',
  })
}

// 获取设备参数列表
export function paraList(data: any) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    headers: token,
    url: '/goods/set/param/getList',
    method: 'post',
    data,
  })
}

// 新增或修改设备参数
export function paraSave(data: any) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    headers: token,
    url: '/goods/set/param/save',
    method: 'post',
    data,
  })
}

// 批量禁用或启用设备参数
export function paraDisable(data: any, status: boolean) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    headers: token,
    url: '/goods/set/param/',
    method: 'put',
    data,
    params: { status },
  })
}

// 批量删除设备参数
export function paraDelete(data: any) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    headers: token,
    url: '/goods/set/param/',
    method: 'delete',
    data,
  })
}

// 获取参数字段列表
export function paraFieldList(data: any, paramId: any) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    headers: token,
    url: '/goods/set/param/' + paramId,
    method: 'post',
    data,
  })
}

// 新增或修改设备参数字段
export function paraFieldSave(data: any) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    headers: token,
    url: '/goods/set/param/saveParamField',
    method: 'post',
    data,
  })
}

// 批量禁用或启用设备参数
export function paraFieldDisable(data: any, params: boolean) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    headers: token,
    url: '/goods/set/param/disableParamField',
    method: 'put',
    data,
    params,
  })
}

// 批量删除参数字段
export function paraFieldDelete(data: any) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    headers: token,
    url: '/goods/set/param/deleteParamField',
    method: 'delete',
    data,
  })
}

// 获取参数字段信息
export function paraFieldInfo(id: string) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    headers: token,
    url: '/goods/set/param/getParamFieldInfo/' + id,
    method: 'get',
  })
}

/**
 * 保存或修改保修政策
 * @param {GoodAPIRequest.SaveGoodWarrantyPolicy} data - 保修政策对象
 */
export const goodWarrantyPolicySave = (
  data: GoodAPIRequest.SaveGoodWarrantyPolicy,
): AxiosPromise<APIResponse> => {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    headers: token,
    url: '/goods/warranty/policy/save',
    method: 'post',
    data,
  })
}

/**
 * 获取保修政策列表
 * @param {GoodAPIRequest.GetWarrantyPolicys} data - 请求参数
 */
export const getWarrantyPolicys = (
  data: GoodAPIRequest.GetWarrantyPolicys,
): AxiosPromise<GoodAPIResponse.WarrantyPolicyList> => {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    headers: token,
    url: '/goods/warranty/policy/getList',
    method: 'post',
    data,
  })
}

/**
 * 获取保修政策详情
 * @param {String} id - 保修政策id
 */
export const getWarrantyPolicyDetail = (
  id: string,
): AxiosPromise<GoodAPIResponse.WarrantyPolicyDetail> => {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    headers: token,
    url: `/goods/warranty/policy/getDetail/${id}`,
    method: 'get',
  })
}

/**
 * 批量启用/禁用保修政策
 * @param {Array<string>} ids - 保修政策id集合
 * @param {Boolean} status - 保修政策状态：false-启用，true-禁用
 */
export const goodWarrantyPolicysDiable = (
  ids: Array<string>,
  status: boolean,
): AxiosPromise<APIResponse> => {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    headers: token,
    url: '/goods/warranty/policy/disabled',
    method: 'post',
    params: {
      status,
    },
    data: ids,
  })
}

/**
 * 批量移动端显示/隐藏保修政策
 * @param {Array<string>} ids - 保修政策id集合
 * @param {Boolean} mobileShow - 移动端是否显示：false-隐藏，true-显示
 */
export const goodWarrantyPolicyMobileShow = (
  ids: Array<string>,
  mobileShow: boolean,
): AxiosPromise<APIResponse> => {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    headers: token,
    url: '/goods/warranty/policy/mobileShow',
    method: 'post',
    params: { mobileShow },
    data: ids,
  })
}

/**
 * 批量删除保修政策
 * @param {Array<string>} ids - 保修政策id集合
 */
export const goodWarrantyPolicyDelete = (ids: Array<string>): AxiosPromise<APIResponse> => {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    headers: token,
    url: '/goods/warranty/policy/delete',
    method: 'post',
    data: ids,
  })
}

/**
 * 批量修改设备分类共享范围
 * @param ids - 设备分类ID集合
 * @param visibilityType - 共享范围：1-全部可见，2-部门可见，3-公司可见
 */
export const goodTypeVisibleTypeMultipleUpdate = (
  ids: Array<string>,
  visibilityType: 1 | 2 | 3,
): AxiosPromise<APIResponse> => {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    headers: token,
    url: '/goods/set/type/updateVisibilityType',
    method: 'post',
    data: ids,
    params: {
      visibilityType,
    },
  })
}

/**
 * 批量启用或禁用批量管理
 * @param {{enableBatchNo: boolean, batchNoGoodsVos: Array<{goodsId: string, type: 1 | 2}>}} data - 请求参数
 */
export const multipleEnableOrDisableBatchNo = (data: {
  enableBatchNo: boolean
  batchNoGoodsVos: Array<{ goodsId: string; type: 1 | 2 }>
}): AxiosPromise<APIResponse> => {
  return request({
    url: '/goods/updateEnableBatchNo',
    method: 'post',
    data,
  })
}
